<?php
header("Content-type:text/html;charset=utf-8");
function cookieFn($name,$value=null,$overtime=0,$path='/'){
    $num=  func_num_args();//获得函数参数个数
    switch ($num){
        case 1:
            return @$_COOKIE[$name];//读取cookie
            break;
        case 2:
            return setcookie($name,$value);//设置和删除cookie
            break;
        case 3:
            return setcookie($name,$value,$overtime);//设置cookie，值、过期时间
            break;
        case 4:
            return setcookie($name,$value,$overtime,$path);//设置cookie，值、过期时间、作用路径
            break;
    }    
}
cookieFn("webname","后盾网");//设置值
//cookieFn("webname","后盾网",time()+3600);//设置cookie，值、过期时间
//cookieFn("webname","后盾网",time()+3600,'/');//设置cookie，值、过期时间、作用路径
//cookieFn("webname",NULL);//删除cookie
echo cookieFn("webname");
?>
